package com.ram.service.impl;

import com.ram.mapper.RoomMapper;
import com.ram.pojo.Room;
import com.ram.pojo.RoomDTO;
import com.ram.pojo.RoomVO;
import com.ram.pojo.PageResult;
import com.ram.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {
    @Autowired
    private RoomMapper roomMapper;

    @Override
    public List<Room> list(Integer buildingId) {
        return roomMapper.list(buildingId);
    }

    @Override
    public Room getById(Integer id) {
        return roomMapper.getById(id);
    }

    @Override
    public void add(Room room) {
        room.setCreateTime(LocalDateTime.now());
        room.setUpdateTime(LocalDateTime.now());
        roomMapper.insert(room);
    }

    @Override
    public void update(Room room) {
        room.setUpdateTime(LocalDateTime.now());
        roomMapper.update(room);
    }

    @Override
    public void deleteById(Integer id) {
        roomMapper.deleteById(id);
    }

    @Override
    public PageResult<RoomVO> pageQuery(RoomDTO dto) {
        // PageHelper.startPage(dto.getPage(), dto.getPageSize());
        List<RoomVO> list = roomMapper.pageQuery(dto);
        long total = roomMapper.countPageQuery(dto);
        return new PageResult<>(total, list);
    }
} 